﻿using UnityEngine;
using System.Collections;

public class Zombie : Character {

    public float moveSpeed = 5;
    public Character target;

    void FixedUpdate()
    {
        if (!target)
        {
            //transform.position = Vector3.MoveTowards(transform.position, transform.position + transform.forward * moveSpeed, moveSpeed * Time.deltaTime);
            rigidbody.MovePosition(transform.position + transform.forward * moveSpeed * Time.deltaTime);
        }
        else
        {
            if (target.HP > 0)
            {
                if (timer >= cooldown)
                {
                    target.TakeDamage(Attack, target.transform.position);
                    timer = 0;
                }
            }
            else
            {
                target = null;
            }
        }
    }

    void OnTriggerStay(Collider other)
    {
        if (other.tag == "Player" || other.tag == "Breakable")
        {

            if (!target)
            {
                target = other.GetComponent<Character>();
            }
        }
    }
}
